package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle.paymentDetails;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.SaveInterceptor;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.common.mybatis.query.CriteriaUpdate;
import com.yycx.common.security.OpenHelper;
import com.yycx.module.bus.client.entity.BusInvoiceunit;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.entity.hy.BusPaymentDetails;
import com.yycx.module.bus.provider.service.BusInvoiceunitService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 保存结算收款账户
 *
 * @author zyf
 */
@Component
public class HyPaymentDetailsSaveHandler implements SaveInterceptor<BusPaymentDetails> {

    @Resource
    private BusPaymentService paymentService;


    @Resource
    private BusInvoiceunitService invoiceunitService;


    @Override
    public void prepare(CriteriaSave cs, EntityMap entityMap, BusPaymentDetails entity) {
        //结算资金支付单ID
        Long paymentId = entity.getPaymentId();
        BusPayment settlePayment = paymentService.getById(paymentId);
        if (FlymeUtils.isNotEmpty(settlePayment)) {
            Long invoiceUnitId = settlePayment.getInvoiceUnitId();
            BusInvoiceunit invoiceunit = invoiceunitService.getById(invoiceUnitId);
            if (FlymeUtils.isNotEmpty(invoiceunit)) {
                entity.setInvoiceUnitName(invoiceunit.getInvoiceunitName());
            }
            entity.setSaleManCode(settlePayment.getSaleManCode());
            entity.setInvoiceUnitId(settlePayment.getInvoiceUnitId());
        }
        entity.setSettleState(0);
        entity.setUserId(OpenHelper.getUserId());
    }

    @Override
    public void prepare(CriteriaUpdate cu, EntityMap params, BusPaymentDetails payment) {

        SaveInterceptor.super.prepare(cu, params, payment);
    }


}
